package com.wanggsx.library.base.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by wanggsx on 15/9/30.
 * 绘制圆环
 */
public class RingView extends View {

    private Paint paint;
    private Context context;
    int center = -1;
    int innerCircle = 0; //设置内圆半径
    int ringWidth = 0; //设置圆环宽度

    public RingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        this.paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        this.paint.setAntiAlias(true); //消除锯齿
        this.paint.setStyle(Paint.Style.STROKE); //绘制空心圆
        this.paint.setDither(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (center == -1) {
            center = getWidth() / 2;
            innerCircle = getWidth() / 2 - 6; //设置内圆半径
            ringWidth = 6; //设置圆环宽度
        }

        //绘制内圆
//        this.paint.setColor(getResources().getColor(R.color.colorGreenDark));
//        this.paint.setStrokeWidth(1);
//        this.paint.setAntiAlias(true);
//        canvas.drawCircle(center, center, innerCircle, this.paint);

        //绘制圆环
        this.paint.setColor(getResources().getColor(Color.parseColor("#ff0000")));
        this.paint.setStrokeWidth(ringWidth);
        this.paint.setAntiAlias(true);
        canvas.drawCircle(center, center, innerCircle + ringWidth / 2, this.paint);

        //绘制外圆
//        this.paint.setARGB(155, 167, 190, 206);
//        this.paint.setStrokeWidth(1);
//        canvas.drawCircle(center, center, innerCircle + ringWidth, this.paint);

    }
}
